CSCI E-92: Application Note 9 How Code Warrior breakpoints interact with reading the SVC instruction operand ------------------------------------------------------------------------------ This application note describes how the Code Warrior debugger sets software breakpoints in code and how that mechanism may interact with reading bytes from instructions. In particular, because our supervisor call number is encoded inside the SVC instruction (as its 8-bit immediate constant operand) and because we read the supervisor call number from the second byte of the SVC instruction, setting a software breakpoint on an SVC instruction may cause undesirable results. The Code Warrior debugger allows users to set software breakpoints in their code by changing the user's instructions in memory to be BKPT instructions. The BKPT instructions are written over the code that would normally execute only during the time when the user's program is running. As soon as the BKPT instruction is encountered and control is given to the debugger, the BKPT instructions are replaced with the user's correct instructions. This implies that if a software breakpoint is set on an SVC instruction, then when our svcHandlerInC function evaluates the expression ((unsigned char *)framePtr->returnAddr)[-2] to read the value of the SVC number, it will instead read the second byte of the BKPT instruction. Therefore, we suggest that software breakpoints should never be placed on SVC instructions. If a breakpoint needs to be placed on an SVC instruction, then a hardware breakpoint may be used. Hardware breakpoints are implemented using address match registers rather than replacing the user's instructions. The number of hardware breakpoints that may be set is limited by the number of address match registers. The debugger user should also be aware that the debugger may need to use some address match registers for certain operations (such as to "step out" of a function).